package com.example.transit.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.transit.R;
import com.example.transit.base.BaseActivity;
import com.example.transit.utils.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {
    @BindView(R.id.serverip)
    EditText serverip;
    @BindView(R.id.svipwarn)
    TextView svipwarn;
    @BindView(R.id.serverport)
    EditText serverport;
    @BindView(R.id.svportwarn)
    TextView svportwarn;
    @BindView(R.id.subserver)
    EditText subserver;
    @BindView(R.id.subserverwarn)
    TextView subserverwarn;
    @BindView(R.id.l_subserver)
    LinearLayout lSubserver;
    @BindView(R.id.basebtn)
    Button basebtn;
    @BindView(R.id.left_mainsetting)
    ImageView leftMainsetting;
    //先写个共享参数；设置配置
    private String server_str;
    private String sp_Server = "server";
    private String portNum;
    private String sp_PortNum = "port";
    private String subServer_str;
    private String sp_subServer = "subserver";


    @Override
    protected boolean isBindEventBus() {
        return false;
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_mainsetting;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        if (!SPUtils.getConfigserverString(getContext(), sp_Server).equals("")) {
            serverip.setText(SPUtils.getConfigserverString(getContext(), sp_Server));
            serverport.setText(SPUtils.getConfigserverString(getContext(), sp_PortNum));
            subserver.setText(SPUtils.getConfigserverString(getContext(), sp_subServer));
        }else{
            serverip.setText("122.112.241.174");
            serverport.setText("10085");
            subserver.setText("Busyingni");
            SPUtils.setConfigserverString(getContext(), sp_Server, "122.112.241.174");
            SPUtils.setConfigserverString(getContext(), sp_PortNum, "10085");
            SPUtils.setConfigserverString(getContext(), sp_subServer, "Busyingni");
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.left_mainsetting,R.id.serverip, R.id.serverport, R.id.svipwarn, R.id.svportwarn, R.id.subserver, R.id.subserverwarn, R.id.l_subserver, R.id.basebtn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_mainsetting:
                Intent intent=new Intent(SettingActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            case R.id.serverip:

                break;
            case R.id.svipwarn:

                break;
            case R.id.serverport:

                break;
            case R.id.svportwarn:
                break;
            case R.id.subserver:

                Log.d("may", "subServer_str1 " + subServer_str);
                Toast.makeText(this, "Configuration indddddddddformation has been submitted.", Toast.LENGTH_LONG).show();
                break;
            case R.id.subserverwarn:
                break;
            case R.id.l_subserver:

                break;
            case R.id.basebtn:
                server_str = serverip.getText().toString();
                portNum = serverport.getText().toString();
                subServer_str = subserver.getText().toString();
                Log.d("may", "subServer_str " + subServer_str);
                SPUtils.setConfigserverString(getContext(), sp_Server, server_str);
                SPUtils.setConfigserverString(getContext(), sp_PortNum, portNum);
                SPUtils.setConfigserverString(getContext(), sp_subServer, subServer_str);
                Toast.makeText(this, "Configuration information has been submitted.", Toast.LENGTH_LONG).show();
                break;
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {//ctrl点播
            Intent intent = new Intent();
            intent.setClass(SettingActivity.this, MainActivity.class);
            startActivity(intent);
            this.finish();
        }
        return super.onKeyDown(keyCode, event);
    }

}
